
/**
 * 医保审核
 *2018.5.14
 */

 addModule({
	name: "Medical Certification",
	
	config : {
		// 播放时长, 毫秒
		duration: 10000,
		//函数图形大小
		r: 30,
		//矩形大小
		rect_h: 30,
		rect_w: 100,
		//表格单元数
		format_w: 2,
		format_h: 3,
		//图像参数

		colors: [],		
		format: [],		
		name: [],		
		link: [],
		
	},

	graphic: {
		opt: null,

		circles: [],

		rects: [],
	},
	
	/**
	 * 本模块的初始化函数
	 */
	init : function() {
		// 调用: 将分镜 (子场景入口函数) 全部加到场景列表中去
		addSceneFunc("grammar-tree", this.stage1, this.name, null);
	},

	stage1:function(){
		var rect = new Array();//生成表格

    	for (var i = 0; i < this.config.format_w; i++) {
    		for (var j = 0; j < this.config.format_h; j++) {
    			var rect_ij = new echarts.graphic.Rect({
    				shape : {
    					width : this.config.rect_w ,
    					height : this.config.rect_h ,
    					x : _width/10 + i*this.config.rect_w,
    					y : _height/3 + j*this.config.rect_h,
    				},
    				style : {
    					fill: this.config.colors[1],
    					text: this.config.format[2*j + i],
    					textFill: '#000000' ,
    					opacity: 0.8
    				}
				});
    			zr.add(rect_ij);
    			rect.push(rect_ij); 			 
    		}
    	}

    	for (var i = 0; i < this.config.format_w; i++) {
    		for (var j = 0; j < this.config.format_w; j++) {
    			var rect_ij = new echarts.graphic.Rect({
    				shape : {
    					width : this.config.rect_w ,
    					height : this.config.rect_h ,
    					x : _width/10 + i*this.config.rect_w,
    					y : _height/4 + j*this.config.rect_h,
    				},
    				style : {
    					fill: this.config.colors[1],
    					text: this.config.format[2*j + i + 6],
    					textFill: '#000000' ,
    					opacity: 0.8
    				}
				});
    			zr.add(rect_ij);
    			rect.push(rect_ij);
    		}
    	}//表格
		
    	this.graphic.rects = rect;

		addRenderFunc("medical-record", function(){
            for (var i = rect.length - 1; i >= 0; i--) {
            	zr.remove(rect[i]);
            }
            endScene();            
            myChart.clear();
        }, {
            once : true,
            delay : this.config.duration
        });


		var option = {
            animationEasingUpdate: 'quinticInOut',
            series : [
                {
                    type: 'graph',
                    symbolSize: 50,
                    label: {
                        normal: {
                            show: true
                        }
                    },
                    edgeSymbol: ['circle', 'arrow'],
                    edgeSymbolSize: [4, 10],
                    edgeLabel: {
                        normal: {
                            textStyle: {
                                fontSize: 20
                            }
                        }
                    },
                    animationDelay : function(idx) {
                    return idx * 1000;
                    },
                    data: [{
                        x: 300,
                        y: 60,  
                        symbolSize: 1,     
                    },{
                        x: 350,
                        y: 60,  
                        symbolSize: 1,     
                    }, {
                        name: this.config.name[3],//age
                        x: 370,
                        y: 50,
                        itemStyle: {color: this.config.colors[2]},
                        symbolSize: [this.config.rect_w, this.config.rect_h],
                        symbol: 'rect',
                    }, {
                        name: this.config.name[4],//15
                        x: 430,
                        y: 50,
                        itemStyle: {color: this.config.colors[3]},
                        symbolSize: [this.config.rect_w, this.config.rect_h],
                        symbol: 'rect',                        
                    }, {
                        name: this.config.name[5],//id-main
                        x: 470,
                        y: 50,
                        itemStyle: {color: this.config.colors[2]},
                        symbolSize: [this.config.rect_w, this.config.rect_h],
                        symbol: 'rect',       
                    }, {
                        name: this.config.name[6],//id-item
                        x: 530,
                        y: 50,
                        itemStyle: {color: this.config.colors[3]},
                        symbolSize: [this.config.rect_w, this.config.rect_h],
                        symbol: 'rect',       
                    }, {
                        name: this.config.name[1],//<
                        x: 400,
                        y: 30,
                        itemStyle
                        : {color: this.config.colors[1]}
                    }, {
                        name: this.config.name[2],//=
                        x: 500,
                        y: 30,
                        itemStyle: {color: this.config.colors[1]}
                    },{
                        name: this.config.name[0],//and
                        x: 450,
                        y: 10,
                    },{
                        x: 450,
                        y: 70,  
                        symbolSize: 1,     
                    }, {
                        name: this.config.name[7],//gingko            
                        x: 450,
                        y: 100,  
                        symbolSize: [this.config.rect_w, this.config.rect_h], 
                        itemStyle: {color: this.config.colors[4]},
                        symbol: 'roundRect',   
                    }, {
                        name: this.config.name[8],//code
                        x: 450,
                        y: 200,
                        itemStyle: {color: this.config.colors[5]},
                        symbolSize: [this.config.rect_w*3, this.config.rect_h*3],
                        symbol: 'rect',       
                    }],
                    links:this.config.link,
                    lineStyle: {
                        normal: {
                            opacity: 0.9,
                            width: 2,
                            curveness: 0
                        }
                    }
                    
                }
            ]
        };
        myChart.setOption(option);

		this.graphic.opt = option;

		addRenderFunc("grammar-tree", function(){
            endScene();
            
            myChart.clear();
        }, {
            once : true,
            delay : this.config.duration
        });
	}


});